from loadLabels import LoadLabels as lls
from matplotlib import pyplot as plt 

label_file = "/home/jerry/dataSet/faces/wider_face_split/wider_face_train_bbx_gt.txt"
root_dir = "/home/jerry/dataSet/faces/WIDER_train/images/"
start, end = 0, 1000

labels = lls(label_file, root_dir, start, end)

sum = 0
scale_hist = {}
while True:
    if not labels.load():
        break
    sum += labels.getFacesCounts()
    faces = labels.getBoundingBoxesList()
    for face in faces:
        _, _, w, h = face
        scale = min(w, h)
        if scale in scale_hist:
            scale_hist[scale] += 1
        else:
            scale_hist[scale] = 1

x = list(scale_hist.keys())
y = list(scale_hist.values())

max_scale = 20
small_sum = 0
for _x in x:
    if _x <= max_scale:
        small_sum += scale_hist[_x]
print(sum, small_sum, small_sum/sum)

plt.bar(x, y)
plt.xlim(min(x), max_scale)
plt.show()
